import { BetaSchemaForm } from '@ant-design/pro-form'
import { PageContainer } from '@ant-design/pro-layout'
import { useAxiosWebGet, useAxiosWebPost } from '@sker/sdk'
import { renderAdminPage } from '@sker/ui'
import { Button, Form } from 'antd'
import { useEffect } from 'react'
export const AccountPage: React.FC<{}> = ({ }) => {
    const { fetch: getSetting } = useAxiosWebGet('imeepos/core/addon/setting')
    const { fetch: saveSetting } = useAxiosWebPost('imeepos/core/addon/setting')
    const { fetch: metadata, loading } = useAxiosWebGet('imeepos/hasura/metadata')
    const [form] = Form.useForm()
    useEffect(() => {
        getSetting({ name: '@imeepos/mq' }).then(res => res.data).then(res => form.setFieldsValue(res))
    }, [])
    return <PageContainer title={'基础设置'} extra={<Button type={'primary'} loading={loading} onClick={async e => {
        await metadata();
    }}>同步Metadata</Button>}>
        <BetaSchemaForm
            columns={[
                { title: '队列地址',tooltip: "如：amqp://root:123qwe@114.67.231.24:5672", dataIndex: 'URL' },
            ]}
            form={form}
            onFinish={async values => {
                await saveSetting({
                    name: '@imeepos/mq',
                    setting: values
                })
            }} />
    </PageContainer>
}
renderAdminPage(AccountPage, 'imeepos/mq/web/setting')
